package com.kili.picture.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.kili.picture.context.exception.DataException;
import com.kili.picture.domain.entity.PictureConfig;
import com.kili.picture.domain.model.picture.config.PictureConfigCreateDTO;
import com.kili.picture.domain.model.picture.config.PictureConfigDetailDTO;
import com.kili.picture.domain.model.picture.config.PictureConfigUpdateDTO;
import com.kili.picture.tools.LocalCacheHolder;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 图片配置 服务类
 * </p>
 *
 * @author Jar
 * @since 2019-04-01
 */
public interface PictureConfigService extends IService<PictureConfig> {

    String CACHE_KEY = "cache.picture.config";

    String DEFAULT = "default";

    /**
     * 获取模块前缀
     *
     * @param module
     * @return
     */
    String getPrefixByModule(String module);

    /**
     * 获取模块前缀
     *
     * @param module
     * @return
     */
    static String getPrefixFromCache(String module) {
        try {
            String prefix;
            if (StringUtils.isEmpty(module)) {
                prefix = DEFAULT;
            } else {
                prefix = LocalCacheHolder.getValue(CACHE_KEY, module, String.class);
            }
            return prefix;
        } catch (Exception e) {
            throw new DataException("get module prefix error");
        }
    }

    /**
     * 获取全部模块前缀
     *
     * @return
     */
    List<String> getPrefixAll();

    PictureConfigDetailDTO create(PictureConfigCreateDTO create);

    /**
     * 修改【修改后会有历史数据问题！！】
     *
     * @param update
     * @return
     */
    PictureConfigDetailDTO update(PictureConfigUpdateDTO update);

}
